package com.hhit.zhgd.task

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
import com.hhit.zhgd.domain.entity.ZhgdMachineryInfo
import com.hhit.zhgd.service.ZhgdMachineryInfoService
import com.hhit.zhgd.utils.compare
import com.hhit.zhgd.utils.formatDate
import com.hhit.zhgd.utils.formatString
import org.quartz.JobExecutionContext
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.scheduling.quartz.QuartzJobBean
import java.util.*


class MachineryMonitorTask:QuartzJobBean() {
    private val log = org.slf4j.LoggerFactory.getLogger(MachineryMonitorTask::class.java)

    @Autowired
    private var zhgdMachineryInfoService: ZhgdMachineryInfoService? = null

    override fun executeInternal(context: JobExecutionContext) {
        log.info("MachineryMonitorTask==>Executing.....")
        val zhgdMachineryInfos =
            zhgdMachineryInfoService?.list(QueryWrapper<ZhgdMachineryInfo>().eq("amount", 0))
        for (zhgdMachineryInfo in zhgdMachineryInfos?: ArrayList()) {
            if (zhgdMachineryInfo.testPlanEndTime?.isNotBlank()==true
                && zhgdMachineryInfo.testEndTime?.isNotBlank()==true
            ) {
                if (Date().formatString("yyyy-MM-dd").formatDate("yyyy-MM-dd")
                        .compare(zhgdMachineryInfo?.testPlanEndTime?.formatDate("yyyy-MM-dd")!!) > 0
                ) {
                    // 设为延期告警
                    zhgdMachineryInfo.status = 4
                    zhgdMachineryInfoService!!.updateById(zhgdMachineryInfo)
                }
            }
        }
    }

}